<?php
namespace Common\Mongo;

class ArticleMongo extends CommonMongo {
    /**
     * 通过文章ID获取文章信息
     *
     * @param     int   $id
     * @return    array $info
     **/
    public function get($id,$cid = 0) {}
    /**
     * 获取文章列表
     *
     * @param     void
     * @return    void
     **/
    public function getList($where) {}
    /**
     * 添加文章到素材库
     *
     * @param     void
     * @return    void
     **/
    public function addArticle() {}
    /**
     * 修改文章库中的文章
     *
     * @param     array $data
     * @return    int   $id
     **/
    public function updateArticle($data) {
        $id = v($data,'id');
        verify($id,'notEmpty','文章ID不能为空');
        verify($id,'isID','非法文章ID');
        $id = intval($id);

        $title = v($data,'title');
        verify($title,'notEmpty','文章标题不能为空');

        $source_name = v($data,'source_name');
        verify($source_name,'notEmpty','来源不能为空');

        $source_url = v($data,'source_url');
        verify($source_url,'notEmpty','来源地址不能为空');

        $author = v($data,'author');
        verify($author,'notEmpty','作者不能为空');

        $hotnum = v($data,'hotnum');
        verify($hotnum,'notEmpty','热度值不能为空');
        verify($hotnum,'isNumber','非法热度值');

        $publishtime = v($data,'publishtime');
        verify($publishtime ,'notEmpty','发布时间不能为空');
        $publishtime = strtotime($publishtime);

        $status = v($data,'status',1,true);
        verify($status,'isStatus','非法状态');

        $content = v($data,'content');
        verify($content,'notEmpty','文章内容不能为空');

        $articleInfo = $this->where(array('id'=>$id))->find();
        verify($articleInfo,'notEmpty','文章不存在');

        if(isset($_FILES['cover']['tmp_name']) && $_FILES['cover']['tmp_name']) {
            $imageInfo = uploadImage('cover','article');
            $cover = $imageInfo ? $imageInfo['path'] : '';
        }else {
            $cover = $articleInfo['cover'];
        }

        $result = $this->save(array(
            'id'            =>  $id, 
            'title'         =>  $title,
            'content'       =>  $content,
            'author'        =>  $author,
            'source_name'   =>  $source_name,
            'source_url'    =>  $source_url,
            'hotnum'        =>  $hotnum,
            'cover'         =>  $cover,
            'publishtime'   =>  $publishtime,
            'updatetime'    =>  NOW_TIME,
            'status'        =>  $status,
        ));

        return $id;
    }
    /**
     * 删除文章
     *
     * @param     void
     * @return    void
     **/
    public function remove($id,$cid) {
    
    }
}
?>
